package com.sbp.message.api.entity;

import com.dap.dao.BasePo;
import com.dap.utils.TraceIdUtils;
import com.sbp.message.api.service.MessageSysInfoService;

import java.util.Date;

public class Message extends BasePo {
    public String id;
    public String destination;
    public String source = MessageSysInfoService.getAppName();//队列对应源系统标识
    public int status = MessageStatus.unconfirmed.getValue();
    public int retry = 0;//重试次数
    public boolean isOrderly = false;  // 是否有序

    public String content;//内容

    public int consumers = 0;//该条消息的将会消费的消费者数量，适应于一对多的订阅
    public String consumersDescribe;///该条消息的将会消费的消费者，适应于一对多的订阅

    public int acknowledges = 0;//当前成功确认数量
    public int businessFailed = 0;  //只能人工处理的业务异常的数量
    public String acknowledgesDescribe = ",";//当前成功确认消费者

    public String unexpectedConsumersDescribe = ","; //意外消费者

    public Date createTime;
    public Date updateTime;
    public Date allowConsumeTime;
    public String traceId;
    public String errorMessage;
    public byte[] errorLog;//错误日志


    public Message() {
        Date date = new Date();
        createTime = date;
        updateTime = date;

        allowConsumeTime = new Date(System.currentTimeMillis()+1000);

        traceId = TraceIdUtils.generateTraceId(false);
    }

    public Message(String destination, String content, boolean isOrderly, Date allowConsumeTime) {
        Date date = new Date();
        this.createTime = date;
        this.updateTime = date;

        this.destination = destination;
        this.content = content;
        this.isOrderly = isOrderly;

        this.allowConsumeTime = allowConsumeTime;

        traceId = TraceIdUtils.generateTraceId(false);
    }
    public Message(String destination, String content, boolean isOrderly) {
        this(destination, content, isOrderly, new Date(System.currentTimeMillis()+1000));
    }
    public Message(String destination, String content) {
        this(destination, content, false);
    }



    public String getId() {
        return id;
    }
    public void setId(String id) {
        this.id = id;
    }

    public String getDestination() {
        return destination;
    }
    public void setDestination(String destination) {
        this.destination = destination;
    }

    public String getSource() {
        return source;
    }
    public void setSource(String source) {
        this.source = source;
    }

    public int getStatus() {
        return status;
    }
    public void setStatus(int status) {
        this.status = status;
    }

    public int getRetry() {
        return retry;
    }
    public void setRetry(int retry) {
        this.retry = retry;
    }

    public boolean getOrderly() {
        return isOrderly;
    }
    public void setOrderly(boolean orderly) {
        isOrderly = orderly;
    }

    public String getContent() {
        return content;
    }
    public void setContent(String content) {
        this.content = content;
    }

    public int getConsumers() {
        return consumers;
    }
    public void setConsumers(int consumers) {
        this.consumers = consumers;
    }

    public String getConsumersDescribe() {
        return consumersDescribe;
    }
    public void setConsumersDescribe(String consumersDescribe) {
        this.consumersDescribe = consumersDescribe;
    }


    public int getAcknowledges() {
        return acknowledges;
    }
    public void setAcknowledges(int acknowledges) {
        this.acknowledges = acknowledges;
    }

    public int getBusinessFailed() {
        return businessFailed;
    }
    public void setBusinessFailed(int businessFailed) {
        this.businessFailed = businessFailed;
    }

    public String getAcknowledgesDescribe() {
        return acknowledgesDescribe;
    }
    public void setAcknowledgesDescribe(String acknowledgesDescribe) {
        this.acknowledgesDescribe = acknowledgesDescribe;
    }


    public String getUnexpectedConsumersDescribe() {
        return unexpectedConsumersDescribe;
    }
    public void setUnexpectedConsumersDescribe(String unexpectedConsumersDescribe) {
        this.unexpectedConsumersDescribe = unexpectedConsumersDescribe;
    }


    public Date getCreateTime() {
        return createTime;
    }
    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public Date getUpdateTime() {
        return updateTime;
    }
    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }

    public Date getAllowConsumeTime() {
        return allowConsumeTime;
    }
    public void setAllowConsumeTime(Date allowConsumeTime) {
        this.allowConsumeTime = allowConsumeTime;
    }

    public String getTraceId() {
        return traceId;
    }
    public void setTraceId(String traceId) {
        this.traceId = traceId;
    }

    public String getErrorMessage() {
        return errorMessage;
    }
    public void setErrorMessage(String errorMessage) {
        this.errorMessage = errorMessage;
    }

    public byte[] getErrorLog() {
        return errorLog;
    }
    public void setErrorLog(byte[] errorLog) {
        this.errorLog = errorLog;
    }



    @Override
    public String toString() {
        return "Message [id=" + id + ", destination=" + destination
               + ", source=" + source + ", status=" + status + ", retry=" + retry
               + ", isOrderly=" + isOrderly + ", content=" + content
               + ", createTime=" + createTime + ", updateTime=" + updateTime + "]";
    }

    @Override
    public int hashCode() {
        return toString().hashCode();
    }

}
